package cn.mesmile.design.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zb
 * @date 2020/11/16 23:36
 * @Description:
 */
public class Folder extends Root {

    List<Root> folders = new ArrayList<>();


    public Folder(String name) {
        super(name);
    }

    public List<Root> getFolders() {
        return folders;
    }

    public void setFolders(List<Root> folders) {
        this.folders = folders;
    }

    @Override
    public void add(Root root) {
        folders.add(root);
    }

    @Override
    public void removeFile(Root root) {
        folders.remove(root);
    }

    @Override
    public void display(int depth) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < depth ; i++) {
            stringBuffer.append("_");
        }
        // 打印横线和当前文件名
        System.out.println(stringBuffer.toString()+ this.getName());
        for (Root folder : folders) {
            // 每个下级，多2ge
            folder.display(depth + 2);
        }

    }


}
